home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 51741 / 51741.xpi / chrome / content / lib / dom.js < prev    next >
Text File  |  2010-02-01  |  3KB  |  113 lines

  1. (function()
  2. {
  3.     //appends an element to the tabbar
  4.     this.appendToTabbar = function (anElement)
  5.     {
  6.         var container = this.getElement('appendToTabbar-container')
  7.         if(container)
  8.         {
  9.             if(this.isThereTreeStyleTab() || this.isThereTabKit())//append the container to the bottom
  10.             {
  11.                 container.insertBefore(anElement, container.firstChild);
  12.                 this.shortChilds(container, 8, true);
  13.             }
  14.             else
  15.             {
  16.                 container.appendChild(anElement);
  17.                 this.shortChilds(container, 8);
  18.             }
  19.         }
  20.         else
  21.         {
  22.             container = this.create('hbox');
  23.             
  24.             var subcontainer = this.create('vbox');
  25.             subcontainer.setAttribute('id', 'metaTitleDescriptionOnTop-appendToTabbar-container');
  26.             
  27.             subcontainer.appendChild(anElement)
  28.             
  29.             if(this.isThereTreeStyleTab() || this.isThereTabKit())//append the container to the bottom
  30.             {
  31.                 var panelcontainer = this.getBrowserElement('status-bar');
  32.                 panelcontainer.parentNode.insertBefore(subcontainer, panelcontainer.parentNode.firstChild);
  33.             }
  34.             else
  35.             {
  36.                 var panelcontainer = document.getAnonymousElementByAttribute(this.getBrowserElement('content'), "anonid", "panelcontainer");
  37.                 panelcontainer.parentNode.insertBefore(subcontainer, panelcontainer.parentNode.lastChild);
  38.             }
  39.         }
  40.     }
  41.     //returns a new element
  42.     this.create = function (elementName)
  43.     {
  44.         return document.createElement(elementName);
  45.     }
  46.     //returns a new text node
  47.     this.createText = function (aString)
  48.     {
  49.         return document.createTextNode(aString);
  50.     }
  51.     //shortcut for document.getElementById
  52.     this.getBrowserElement = function (anID)
  53.     {
  54.         return document.getElementById(anID);
  55.     }
  56.     //return an element of this extension
  57.     this.getElement = function (anID)
  58.     {
  59.         return this.getBrowserElement('metaTitleDescriptionOnTop-'+anID);
  60.     }
  61.     //removes an element from the dom
  62.     this.removeElement = function (anElement)
  63.     {
  64.         if(anElement && anElement.parentNode)//Sometimes the element was removed.
  65.             anElement.parentNode.removeChild(anElement);
  66.     }
  67.     //shorts the childs elements of a node to maxChilds elements
  68.     this.shortChilds = function (anElement, maxChilds, fromTop)
  69.     {
  70.         if(anElement.hasChildNodes())
  71.         {
  72.             var nodesForDeletion = []
  73.             var length = anElement.childNodes.length;
  74.             if(length<=maxChilds)
  75.                 return;
  76.             var nodesToRemove = length-maxChilds;
  77.             var nodesRemoved = 0;
  78.             
  79.             if(fromTop)
  80.             {
  81.                 for(var a=length-1;a>=0;a--)
  82.                 {
  83.                     if(!anElement.childNodes[a].hasAttribute('locked'))
  84.                     {
  85.                         nodesForDeletion[nodesForDeletion.length] = anElement.childNodes[a];
  86.                         nodesRemoved++;
  87.                         if(nodesRemoved == nodesToRemove)
  88.                             break;
  89.                     }
  90.                 }
  91.             }
  92.             else
  93.             {
  94.                 for(var a=0;a<length;a++)
  95.                 {
  96.                     if(!anElement.childNodes[a].hasAttribute('locked'))
  97.                     {
  98.                         nodesForDeletion[nodesForDeletion.length] = anElement.childNodes[a];
  99.                         nodesRemoved++;
  100.                         if(nodesRemoved == nodesToRemove)
  101.                             break;
  102.                     }
  103.                 }
  104.             }
  105.             for(var id in nodesForDeletion)
  106.                 anElement.removeChild(nodesForDeletion[id]);
  107.         }
  108.     }
  109.  
  110.     return null;
  111.  
  112. }).apply(metaTitleDescriptionOnTop);
  113.